<?php

namespace App\Entity\Sale;

use ApiPlatform\Core\Annotation\ApiResource;
use App\Base\Annotation\Common;
use App\Repository\Sale\PromotionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ORM\Entity(repositoryClass=PromotionRepository::class)
 */
class Promotion
{
    /**
     * @Common(cnName="#",listType="text",editType="text")
     * @Groups({"sale"})
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @Common(cnName="活动名称",listType="text",editType="text")
     * @Groups({"sale"})
     * @ORM\Column(type="string", length=255)
     */
    private $name;

    /**
     * @Common(cnName="开始时间",listType="text",editType="datetime",width="180")
     * @Groups({"sale"})
     * @ORM\Column(type="datetime")
     */
    private $startAt;

    /**
     * @Common(cnName="结束时间",listType="text",editType="datetime",width="180")
     * @Groups({"sale"})
     * @ORM\Column(type="datetime")
     */
    private $endAt;

    /**
     * @Common(cnName="主页Banner",listType="text",editType="pics")
     * @Groups({"sale"})
     * @ORM\Column(type="array", nullable=true)
     */
    private $banners = [];

    /**
     * @Common(cnName="主页背景色",listType="text",editType="text")
     * @Groups({"sale"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $bgColor;

    /**
     * @Common(cnName="主页背景图",listType="text",editType="pic")
     * @Groups({"sale"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $bgImage;

    /**
     * @Common(cnName="会场",listType="text",editType="text")
     * @Groups({"sale"})
     * @ORM\OneToMany(targetEntity=PromotionCategory::class, mappedBy="promotion", orphanRemoval=true)
     */
    private $categories;

    /**
     * @Common(cnName="快捷输入",listType="text",editType="text")
     * @Groups({"sale"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $fastInputText;

    public function __construct()
    {
        $this->categories = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getStartAt(): ?\DateTimeInterface
    {
        return $this->startAt;
    }

    public function setStartAt(\DateTimeInterface $startAt): self
    {
        $this->startAt = $startAt;

        return $this;
    }

    public function getEndAt(): ?\DateTimeInterface
    {
        return $this->endAt;
    }

    public function setEndAt(\DateTimeInterface $endAt): self
    {
        $this->endAt = $endAt;

        return $this;
    }

    public function getBanners(): ?array
    {
        return $this->banners;
    }

    public function setBanners(?array $banners): self
    {
        $this->banners = $banners;

        return $this;
    }

    public function getBgColor(): ?string
    {
        return $this->bgColor;
    }

    public function setBgColor(?string $bgColor): self
    {
        $this->bgColor = $bgColor;

        return $this;
    }

    public function getBgImage(): ?string
    {
        return $this->bgImage;
    }

    public function setBgImage(?string $bgImage): self
    {
        $this->bgImage = $bgImage;

        return $this;
    }

    /**
     * @return Collection|PromotionCategory[]
     */
    public function getCategories(): Collection
    {
        return $this->categories;
    }

    public function addCategory(PromotionCategory $category): self
    {
        if (!$this->categories->contains($category)) {
            $this->categories[] = $category;
            $category->setPromotion($this);
        }

        return $this;
    }

    public function removeCategory(PromotionCategory $category): self
    {
        if ($this->categories->contains($category)) {
            $this->categories->removeElement($category);
            // set the owning side to null (unless already changed)
            if ($category->getPromotion() === $this) {
                $category->setPromotion(null);
            }
        }

        return $this;
    }

    public function getFastInputText(): ?string
    {
        return $this->fastInputText;
    }

    public function setFastInputText(?string $fastInputText): self
    {
        $this->fastInputText = $fastInputText;

        return $this;
    }
}
